﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FluentAssertions;
using FluentValidation;
using FluentValidation.Results;
using NursingHome.Factories;
using NursingHome.Utilities.ExtensionMethods;

namespace NursingHome.Model.Tests
{
    [TestClass]
    public class PatientTests
    {
        [TestMethod]
        public void Name_should_not_be_empty()
        {
            var patient = PatientFactory.Create();

            patient.Name = "";
            
            patient.IsValid.Should().BeFalse();
            patient.Validate().Errors.Count.Should().Be(1);
            patient.Validate().Errors[0].ErrorMessage.Should().Be("'Name' should not be empty.");
        }

        [TestMethod]
        public void Name_should_not_be_null()
        {
            var patient = PatientFactory.Create();

            patient.Name = null;

            patient.IsValid.Should().BeFalse();
            patient.Validate().Errors.Count.Should().Be(1);
            patient.Validate().Errors[0].ErrorMessage.Should().Be("'Name' should not be empty.");
        }

        [TestMethod]
        public void Name_should_not_be_more_than_fifty_characters()
        {
            var patient = PatientFactory.Create();

            patient.Name = "a".Times(51);

            patient.IsValid.Should().BeFalse();
            patient.Validate().Errors.Count.Should().Be(1);
            patient.Validate().Errors[0].ErrorMessage.Should().Be("Name should not be more than 50 characters.");
        }

        [TestMethod]
        public void DOB_should_not_be_an_invalid_date()
        {
            var patient = PatientFactory.Create();

            patient.DOB = "123";

            patient.IsValid.Should().BeFalse();
            patient.Validate().Errors.Count.Should().Be(1);
            patient.Validate().Errors[0].ErrorMessage.Should().Be("Date of birth is not a valid date.");
        }
    }
}
